﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataAccess
{
    class HowToUserDataAccess
    {
        private void Demo()
        {
            string err;

            #region Create Connection With Connection String.
            DataAccessClient dal = new DataAccessClient(String.Format("User Id={0};Password={1};Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL={2})(HOST={3})(PORT={4})))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME={5})));",
                                                        "usrauth",
                                                        "usrauthdev",
                                                        "TCP",
                                                        "10.100.98.19",
                                                        "1521",
                                                        "authdev"));
            #endregion

            #region Create Connection With TRN Name. (Must Set DataSource, Username, Password in Config File)
            // DataAccessClient dal = new DataAccessClient(DATABASE_PROXY.AUTH);
            #endregion

            #region insert
            //p_APPLICATION app = new p_APPLICATION();
            //app.APPLNO = "A00";
            //app.APPLNAME = "AnulitApp2";
            //app.DESCRIPTION = "description";
            //app.COMPANY_CODE = "HP00";
            //app.MOBILEURL = "http://google.co.th";

            //if (dal.Insert(app, out err) == DB_RESULT.COMPLETED)
            //{

            //}
            #endregion

            #region update
            //p_APPLICATION app = new p_APPLICATION();
            //app.APPLNAME = "AnulitApp2";
            //app.DESCRIPTION = "description";
            //app.COMPANY_CODE = "HP00";
            //app.UPDDATE = DateTime.Now;
            //app.MOBILEURL = "http://google.co.th";

            //app.setCriteria(p_APPLICATION_FIELD.APPLNO, CRITERIA_FLAG.Equal, "A00");
            //app.setCriteria(p_APPLICATION_FIELD.APPLNAME, CRITERIA_FLAG.Equal, "Anulit App2");
            //app.setOperator(OPERATOR.OR);

            //app.clearCriteria(); // Criteria ที่ Set ทั้งหมด

            //if (dal.Update(app, out err) == DB_RESULT.COMPLETED)
            //{

            //}
            #endregion

            #region delete
            //p_APPLICATION app = new p_APPLICATION();

            //app.setCriteria(p_APPLICATION_FIELD.APPLNO, CRITERIA_FLAG.Equal, "A00");
            //app.setCriteria(p_APPLICATION_FIELD.APPLNAME, CRITERIA_FLAG.Equal, "AnulitApp2");
            //app.setOperator(OPERATOR.AND);

            //app.clearCriteria(); // Criteria ที่ Set ทั้งหมด

            //if (dal.Delete(app, out err) == DB_RESULT.COMPLETED)
            //{

            //}
            #endregion

            #region ExecuteNonQuery (Without Hastable)
            //int rows_affect;
            //if (dal.ExecuteNonQuery("insert into application (APPLNO, APPLNAME, COMPANY_CODE, DESCRIPTION) " +
            //                        "values ('A00', 'test', 'MH00', 'mydesc')", null, out rows_affect, out err) == DB_RESULT.COMPLETED)
            //{

            //}
            #endregion

            #region ExecuteNonQuery (With Hashtable)
            //int rows_affect;
            //Hashtable h = new Hashtable();
            //h.Add(":APPLNO", "A00");
            //h.Add(":APPLNAME", "test");
            //h.Add(":COMPANY_CODE", "MH00");
            //h.Add(":DESCRIPTION", "mydesc");
            //if (dal.ExecuteNonQuery("insert into application (APPLNO, APPLNAME, COMPANY_CODE, DESCRIPTION) " +
            //                        "values (:APPLNO, :APPLNAME, :COMPANY_CODE, :DESCRIPTION)", h, out rows_affect, out err) == DB_RESULT.COMPLETED)
            //{

            //}
            #endregion

            #region ExecuteScalar (Without Hastable)
            //object data_return;
            //if (dal.ExecuteScalar("select * from application t order by t.applno", null, out data_return, out err) == DB_RESULT.COMPLETED)
            //{

            //}
            #endregion

            #region ExecuteScalar (With Hastable)
            //object data_return;
            //Hashtable h = new Hashtable();
            //h.Add(":APPLNO", "A00");
            //if (dal.ExecuteScalar("select * from application t where t.applno = :APPLNO", h, out data_return, out err) == DB_RESULT.COMPLETED)
            //{

            //}
            #endregion

            #region ExecuteAdaptor (Without Hastable)
            //DataTable data_dt;
            //if (dal.ExecuteAdaptor("select * from application t order by t.applno", null, out data_dt, out err) == DB_RESULT.COMPLETED)
            //{

            //}
            #endregion

            #region ExecuteAdaptor (With Hastable)
            //DataTable data_dt;
            //Hashtable h = new Hashtable();
            //h.Add(":APPLNO", "A33");
            //if (dal.ExecuteAdaptor("select * from application t where t.applno = :APPLNO", h, out data_dt, out err) == DB_RESULT.COMPLETED)
            //{

            //}
            #endregion

            #region SelectDataToList

            //List<p_APPLICATION> my_List = dal.SelectDataToList<p_APPLICATION>(out err);

            #endregion

            #region SelectDataToDataTable

            //DataTable my_Table = dal.SelectDataToDataTable<p_APPLICATION>(out err);

            #endregion
        }
    }
}
